package com.hundsun.fcp.adapter;

import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.widget.BaseAdapter;

public abstract class Adapter<T> extends BaseAdapter {
	
	protected int mLayoutResId;

	protected ArrayList<T> mDataList;

	protected LayoutInflater mInflater;
	
	protected Context mContext;

	public Adapter(Context context, int resource, ArrayList<T> list) {
		this.mLayoutResId = resource;
		this.mDataList = list;
		this.mContext = context;
		this.mInflater = LayoutInflater.from(context);
	}
	
	public Adapter(Context context, int resource) {
		this(context, resource, null);
	}

	@Override
	public int getCount() {
		return mDataList != null ? mDataList.size() : 0;
	}

	public void setData(ArrayList<T> list) {
		this.mDataList = list;
	}
	
	public void addData(ArrayList<T> list){
		if(this.mDataList ==null){
			mDataList = new ArrayList<T>() ;
		}
		mDataList.addAll(list) ;
		
		try {
			this.notifyDataSetChanged() ;
		} catch (Exception e) {
				e.printStackTrace();
			}
		}

	
	public void removeData(ArrayList<T> list){
		if(this.mDataList !=null){
			mDataList.removeAll(list) ;
		}
	}

	@Override
	public T getItem(int position) {
		if(mDataList==null)
			return null ;
		return mDataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}
	
	public void clear(){
		if(mDataList!=null)
			mDataList.clear() ;
	}
	
	public ArrayList<T> getList(){
		return mDataList ;
	}
}
